package org.hk.basic.studyspring;

import javafx.application.Application;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class Computer {
    private USB usb;

    public USB getUsb() {
        return usb;
    }

    public void setUsb(USB usb) {
        this.usb = usb;
    }

    public void keyPress(String value){
        usb.input(value);
    }

    public static void main(String[] args) {
        //application 應用 context 上下文
        //ApplicationContext ctx =  new FileSystemXmlApplicationContext("src/main/resources/applicationContext.xml");
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        Computer computer = (Computer)ctx.getBean("computer");
        computer.keyPress("k");
    }
}
interface USB{
    public void input(String val);
    public String output();
}
//适配器
abstract class KeyBoard implements USB{
    public abstract void keyPress(String val);
    public String output(){
        return null;
    }
}

class MiroBoard extends  KeyBoard{

    @Override
    public void keyPress(String val) {
        System.out.println("微软键盘打字打出了"+val);
    }

    @Override
    public void input(String val) {
        keyPress(val);
    }


}
class LogitechBoard extends KeyBoard{

    @Override
    public void keyPress(String val) {
        System.out.println("罗技键盘打字打出了"+val);
    }

    @Override
    public void input(String val) {
        keyPress(val);
    }

}
